<?php

namespace backend\models;

use Yii;

/**
 * This is the model class for table "mall_business".
 *
 * @property int $id
 * @property int $uid 用户id
 * @property int $status 状态
 * @property string $avatar 头像
 * @property string $name 名字
 * @property string $address 商店地址
 * @property int $update_time 修改时间
 * @property int $create_time 创建时间
 * @property string $ad 广告
 */
class MallBusiness extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'mall_business';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['uid', 'name', 'update_time', 'create_time' , 'status'], 'required'],
            [['uid', 'update_time', 'create_time', 'status'], 'integer'],
            [['avatar'], 'string', 'max' => 255],
            [['ad'], 'string'],
            [['name'], 'string', 'max' => 100],
            [['address'], 'string', 'max' => 60],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'uid' => '商家ID',
            'avatar' => '头像',
            'name' => '商城名称',
            'address' => '地址',
            'update_time' => '修改时间',
            'create_time' => '创建时间',
            'status' => '状态',
        ];
    }

    public function getUser()
    {
        return $this->hasOne(EduUser::class, ['id' => 'uid']);
    }

    public static function attributeValue()
    {
        return [
            'status' => [
                '1' => '正常',
                '-1' => '禁用',
            ],
        ];
    }

    public function getStatusValue()
    {
        switch ($this->status)
        {
            case -1:
                $value = '禁用';
                break;
            case 1:
                $value= '正常';
                break;
            default:
                $value = '未知';
                break;
        }
        return $value;
    }
}
